# Pool.py 
# VHP-2, slawek@rozbicki.eu

from App import App

class Pool:
	u"Pool"
	def __init__(self):
		u""
		self.app_table = []
        def __repr__(self):
                return u"Pool Class (%d)" % len(self.app_table)
	def _AppLookup(self, vhost):
		for i in range(len(self.app_table)):
			if self.app_table[i].Name() == vhost:			
				return i
		return -1
	def SendLine(self, line):
		app_index = self._AppLookup(line['vhost'])
		#print app_index
		if app_index == -1:
			A = App(line)
			self._AddApp(A)
		else:
			self._InsertRecord(app_index, line)
	def _AddApp(self, App):
		self.app_table.append(App)
	def _InsertRecord(self, app_index, record):
		App = self.app_table[app_index]
		App.Append(record)	
